# 雷达迷你设计任务 sample01007.md
from typing import Dict
import argparse
import numpy as np
from conf.app_config import AppConfig as AC

class MiniDesign01(object):
    def __init__(self):
        self.name = ''

    @staticmethod
    def design(
        delta_R:float = 150.0, Theta_A:float = 360.0, Theta_E:float = 10.0,
        sigma_m:float = -10.0, sigma_a:float = 6.0,
        T_sc:float = 2.0, T_e:float = 290.0,
        F:float = 8.0, L=10.0, f_0:float = 2.0E9, SNR = 15,
        R_m:float = 2000.0, R_a:float = 10000.,
        R_max:float = 60E3, A_e:float = 1.75, rho:float = 0.8
    ) -> None:
        print(f'迷你雷达设计场景')
        tau = 2*delta_R / AC.C
        B = AC.C / (2*delta_R)
        print(f'tau={tau}; B={B};')
        Omega = Theta_A * Theta_E / (57.296**2)
        print(f'Omega={Omega};')

        T_e_db = 10 * np.log10(T_e)
        R_m_db = 10 * np.log10(R_m)
        Omega_db = 10 * np.log10(Omega)
        T_sc_db = 10 * np.log10(T_sc)
        R_max_db = 10 * np.log10(R_max)
        PAP_m_db = SNR - sigma_m - T_sc_db + 10 * np.log10(4 * np.pi) + 4.0 * R_max_db + AC.k + T_e_db + F + L + Omega_db
        PAP_a_db = SNR - sigma_a - T_sc_db + 10 * np.log10(4 * np.pi) + 4.0 * R_max_db + AC.k + T_e_db + F + L + Omega_db
        print(f'PAP0_m={PAP_m_db}; PAP0_a={PAP_a_db};')
        PAP_db = 0.0
        if PAP_m_db > PAP_a_db:
            PAP_db = PAP_m_db
        else:
            PAP_db = PAP_a_db
        P_av = 10**(PAP_db/10.0) / A_e
        print(f'P_av: {P_av};')
        A = A_e / rho
        print(f'A: {A};')
        lambda_ = AC.C / f_0
        G = (4*np.pi*A_e)/lambda_**2
        print(f'G: {G};')
        # FAN beam
        theta_e = Theta_E
        theta_a = 26000 / (G * theta_e)
        print(f'theta_a: {theta_a}; 弧度: {np.pi/180.0*theta_a};')

def main(params:Dict = {}) -> None:
    MiniDesign01.design()

def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--run_mode', action='store',
        type=int, default=1, dest='run_mode',
        help='run mode'
    )
    return parser.parse_args()

if '__main__' == __name__:
    args = parse_args()
    params = vars(args)
    main(params=params)
